<?php
/*
Copyright (C) 2009 de Flotte Maxence

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
?>
<?php
//Test de fonctionnement de lecture d'une étiquette avec des ZzS
//error_reporting(0);
//Bibliothèque puZZle et objets de base de puZZle
$temps1 = microtime(true);
	include_once './ZzL/Main.php';
	//include_once './ZzO/Main.php';
	//include_once './ZzL/Conf.php';
$temps2 = microtime(true);

//Session
	session_start();

//Conexion mysql
	$GLOBALS['MySql'] = $mySql = new mysqli($GLOBALS['Serveur'], $GLOBALS['Login'], $GLOBALS['PassWord'], $GLOBALS['DB']);


//Le répertoire courant
	$GLOBALS['cwd'] = getcwd();
//logout
	if(isset($_GET['action']) and $_GET['action'] == 'logout') {
		$_POST['action'] = 'logout';
		include 'login.php';
	}

//Login
	//Si session invalide
	if(!isSet($_SESSION['user'])) {
		$_SESSION['user'] = 0;
		$_SESSION['group'] = array();
	}
	//Si session vide
	if(empty($_SESSION['user'])) {
		//Si il y a une demande de connection
		if(!empty($_POST['pseudo']))
			$_POST['action'] = 'login';
		//Reconnection du user
		elseif(isset($_COOKIE['user']) and isset($_COOKIE['passCookie']))
			$_POST['action'] = 'reConnect';
		include 'login.php';
	}
	//Si demande de déconnexion
	elseif(isSet($_GET['logout'])) {
		$_POST['action'] = 'logout';
		include 'login.php';
	}
	elseif(isSet($_SESSION['nextTimestampToReloadGroups']) and $_SESSION['nextTimestampToReloadGroups'] < time()) {
		//On defini la prochaine actualisation des groupes
			if($GLOBALS['reloadGroupEvery'] >= 0)
				$_SESSION['nextTimestampToReloadGroups'] = time()+$GLOBALS['reloadGroupEvery'];
		include 'login.php';
		setSessionGroups($_SESSION['user']);
	}

//on récupère le label si il est dans l'adresse sinon on l'atribue automatiquement

	if(isset($_GET['label'])) {
		$label = explode('-',$_GET['label']);
		$label = intval($label[0]);
	}
	else
		$label = $_GET['label'] = 1;


$temps3 = microtime(true);
//On charge le puzzle
loadLabel();


$temps4 = microtime(true);
echo '<br/>Temps d\'execution totale : '.round($temps4 - $temps1, 4).'<br/>';
echo 'Temps des includes : '.round($temps2 - $temps1, 4).'<br/>';
echo 'Temps des autres opérations : '.round($temps3 - $temps2, 4).'<br/>';
echo 'Temps de génération : '.round($temps4 - $temps3, 4).'<br/>';
echo time();
?>